home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 6.3 KB | 220 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWCFMRes.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWFILES_H
- #include "FWFiles.h"
- #endif
-
- #ifdef FW_BUILD_MAC
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
-
- #if defined(SYMANTEC_CPLUS) && !FW_LIB_EXPORT_PRAGMAS
- #pragma internal on
- #endif
-
- #endif
-
- //========================================================================================
- // Global Variable
- //========================================================================================
- // FW_gInstance is initialized in InitLibraryResources on the Mac
- // FW_gInstance is defined in FWLbInit.cpp for Windows
- #ifdef FW_BUILD_MAC
- FW_Instance FW_gInstance = NULL;
- #endif
-
- //========================================================================================
- // Global functions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // InitLibraryResources
- //----------------------------------------------------------------------------------------
-
- OSErr InitLibraryResources(CFragInitBlockPtr init)
- {
- switch( init->fragLocator.where )
- {
- case kDataForkCFragLocator:
- case kResourceCFragLocator:
- FW_gInstance = (FW_Instance) NewPtr(sizeof(FSSpec));
- if( MemError() )
- return MemError();
- *FW_gInstance = *init->fragLocator.u.onDisk.fileSpec;
- break;
-
- case kMemoryCFragLocator:
- // An in-memory fragment does not have any resource fork.
- // Any future calls to Begin... will fail (see below)
- break;
-
- default:
- ::DebugStr((unsigned char*) "\pUnknown segment location!");
- break;
- }
- return noErr;
- }
-
- #endif
-
- //========================================================================================
- // class FW_CAcquireCFMResourceAccess
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- short FW_CAcquireCFMResourceAccess::gLibraryRefCount; // C++ gauranteed to be 0
- short FW_CAcquireCFMResourceAccess::gLibraryRefNum = -1;
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess()
- {
- #ifdef FW_BUILD_MAC
- CommonInit(FW_gInstance);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess(FW_Instance instance)
- {
- #ifdef FW_BUILD_MAC
- CommonInit(instance);
- #endif
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::CommonInit
- //----------------------------------------------------------------------------------------
-
- void FW_CAcquireCFMResourceAccess::CommonInit(FW_Instance instance)
- {
- FW_ASSERT(instance != NULL);
-
- fSavedLibraryRefNum = ::CurResFile();
-
- if (gLibraryRefCount == 0)
- {
- gLibraryRefNum = ::FSpOpenResFile(instance, fsRdPerm);
- FW_FailOnError(::ResError());
- }
-
- ::UseResFile(gLibraryRefNum);
- FW_FailOnError(::ResError());
- gLibraryRefCount++;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireCFMResourceAccess::~FW_CAcquireCFMResourceAccess
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireCFMResourceAccess::~FW_CAcquireCFMResourceAccess()
- {
- #ifdef FW_BUILD_MAC
- if(--gLibraryRefCount == 0)
- {
- ::CloseResFile(gLibraryRefNum);
- gLibraryRefNum = -1;
- }
-
- ::UseResFile(fSavedLibraryRefNum);
- #endif
- }
-
- //========================================================================================
- // class FW_CSharedLibraryResourceFile
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile
- //----------------------------------------------------------------------------------------
-
- FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile():
- FW_CResourceFile()
- #ifdef FW_BUILD_MAC
- ,fAcquireCFMResourceAccess(FW_gInstance)
- #endif
- {
- CommonInit(FW_gInstance);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile
- //----------------------------------------------------------------------------------------
-
- FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile(FW_Instance instance):
- FW_CResourceFile()
- #ifdef FW_BUILD_MAC
- ,fAcquireCFMResourceAccess(instance)
- #endif
- {
- CommonInit(instance);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSharedLibraryResourceFile::CommonInit
- //----------------------------------------------------------------------------------------
-
- void FW_CSharedLibraryResourceFile::CommonInit(FW_Instance instance)
- {
- #ifdef FW_BUILD_MAC
- FW_PPrivResourceFile privResourceFile(new FW_CPrivResourceFileRep(fAcquireCFMResourceAccess.GetLibraryRefNum()));
- #endif
- #ifdef FW_BUILD_WIN
- FW_PPrivResourceFile privResourceFile(new FW_CPrivResourceFileRep(instance));
- #endif
-
- SetRep(privResourceFile);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSharedLibraryResourceFile::~FW_CSharedLibraryResourceFile
- //----------------------------------------------------------------------------------------
-
- FW_CSharedLibraryResourceFile::~FW_CSharedLibraryResourceFile()
- {
- }
-